from lib.ZSprite import ZSprite
from res.fun import _create_rect

color = [48 , 177 , 63]

class HealthBar(ZSprite ):
    def __init__(self , health):
        super(HealthBar , self).__init__()
        self.size = [30 , 2]
        self.width = self.size[0]
        self.maxhealth = health
        self.surface = _create_rect(color , self.size , 0)
        self.rect = self.surface.get_rect()
        self.margintop = 10
        self.marginleft = 3
        self.isRunning = True

    def draw(self , health):
        if self.isRunning :
            point = float(health) / float(self.maxhealth)
            self.size[0] = point * self.width
            self.surface = _create_rect(color , self.size , 0)
            self.screen.blit(self.surface , self.rect.topleft)
